package com.lemon.smartsafety.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.RelativeLayout;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.utils.CommonUtil;
import com.lemon.smartsafety.view.ViewRadarTitle;
import com.lemon.smartsafety.view.radar.RadarView;

/**
 * 项目名称：workspace
 * 类描述：
 * 创建人：Fargo
 * 创建时间：2016/8/9 14:28
 * 修改人：Fargo
 * 修改时间：2016/8/9 14:28
 * 修改备注：
 */
public class DialogRadarView {

    private Context mContext;

    private Dialog dialog;

    private String[] titles;
    private double[] data1;
    private double[] data2;

    private String  strTitle1="",strTitle2="";

    public DialogRadarView(Context mContext) {
        this.mContext = mContext;
    }

    public interface ClickBackInterface {
        public void callBackFunction(View view, int i);

    }

    public String[] getTitles() {
        return titles;
    }

    public void setTitles(String[] titles) {
        this.titles = titles;
    }

    public double[] getData1() {
        return data1;
    }

    public void setData1(double[] data1) {
        this.data1 = data1;
    }

    public double[] getData2() {
        return data2;
    }

    public void setData2(double[] data2) {
        this.data2 = data2;
    }

    public String getStrTitle1() {
        return strTitle1;
    }

    public void setStrTitle1(String strTitle1) {
        this.strTitle1 = strTitle1;
    }

    public String getStrTitle2() {
        return strTitle2;
    }

    public void setStrTitle2(String strTitle2) {
        this.strTitle2 = strTitle2;
    }

    public void init(Context context){

        dialog = new Dialog(context, R.style.dialog_style);
        dialog.setContentView(R.layout.dialog_radarview);
        Window win = dialog.getWindow();
        win.setGravity(Gravity.CENTER);
        win.setWindowAnimations(R.style.DialogAnimationFade);
        win.setLayout(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        dialog.setCanceledOnTouchOutside(true);


        RadarView  radarView=(RadarView)dialog.findViewById(R.id.radarView);
        ViewRadarTitle viewRadarTitle=(ViewRadarTitle)dialog.findViewById(R.id.viewRadarTitle);


        if(!CommonUtil.strIsEmpty(strTitle1)){
            viewRadarTitle.setVisibility(View.VISIBLE);
            viewRadarTitle.setTitle1(strTitle1);
            viewRadarTitle.setTitleImg1(ContextCompat.getColor(context, R.color.txt_color2));
        }else{
            viewRadarTitle.setVisibility(View.GONE);
        }

        if(!CommonUtil.strIsEmpty(strTitle2)){
            viewRadarTitle.setTitle2(strTitle2);
            viewRadarTitle.setTitleImg2(ContextCompat.getColor(context, R.color.txt_color3));
        }


        if(titles!=null) {
            radarView.setTitles(titles);
        }
        if(data1!=null) {
            radarView.setDataOne(data1);
        }
        if(data2!=null) {
            radarView.setDataTwo(data2);
        }
        if(titles!=null) {
            radarView.setCount(titles.length);
        }
        radarView.resetShow();

        radarView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });


        if(dialog!=null)
            dialog.show();

    }

}
